﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace TableTool
{
    public partial class CEL占星 : Form
    {
        /// <summary>
        /// 打开时间
        /// </summary>
        DateTime opentime {  get; set; }
        private bool MouseFlag { get; set; }
        public bool reFlag { get; set; }
        private Point mouse { get; set; }
        public CEL占星()
        {
            InitializeComponent();
            DoubleBuffered = true;
            this.Load += CEL占星_Load;
            this.label1.MouseDown += AlarmFrm_MouseDown;
            this.label1.MouseMove += AlarmFrm_MouseMove;
            this.label1.MouseUp += AlarmFrm_MouseUp;
        }
        private void AlarmFrm_MouseUp(object? sender, MouseEventArgs e)
        {
            MouseFlag = false;
            ElsTool.usdata.cel_x=this.Location.X;
            ElsTool.usdata.cel_y=this.Location.Y;
        }

        private void AlarmFrm_MouseMove(object? sender, MouseEventArgs e)
        {
            if (MouseFlag)
            {
                this.Location = new Point(MousePosition.X - mouse.X,
                   MousePosition.Y - mouse.Y);
            }
        }

        private void AlarmFrm_MouseDown(object? sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Left)
            {
                mouse = new Point(e.X, e.Y);
                MouseFlag = true;
            }
        }
        private void CEL占星_Load(object? sender, EventArgs e)
        {
            opentime=DateTime.Now;
            label1.ForeColor = Color.White;
            timer1.Start();
            ShowInTaskbar = false;
            TopMost= true;
            this.Location = new Point(ElsTool.usdata.cel_x,ElsTool.usdata.cel_y);
        }

        private void button2_Click(object sender, EventArgs e)
        {
            reFlag=true;
        }

        private void button1_Click(object sender, EventArgs e)
        {
            timer1.Stop();
            this.Close();
        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            if (reFlag)
            {
                opentime = DateTime.Now;
                reFlag = false;
            }
            string str = "{0}-{1}";
            Color font = Color.White;
            Color back = Color.White;
            var dst = DateTime.Now - opentime;
            var seconds=(int)dst.TotalSeconds;
            if (seconds>=0&& seconds < 20)
            {
                str = string.Format(str, seconds, "收集");
                back = Color.Blue;
            }
           else if (seconds >= 20 && seconds < 40)
            {
                str = string.Format(str, seconds, "空亡");
                back = Color.Purple;
            }
            else if (seconds >= 40 && seconds < 55)
            {
                str = string.Format(str, seconds, "审判");
                back = Color.Yellow;
                font = Color.Black;
            }
           else
            {
                str = string.Format(str, seconds, "中天");
                back = Color.Red;
                if (seconds >= 60)
                {
                    opentime = DateTime.Now;
                }
            }

            
            label1.Text = str;
            label1.ForeColor= font;
            label1.BackColor= back;
        }
    }
}
